package org.dairy.farms.dao.hibernate;

import org.dairy.farms.dao.NotesDAO;
import org.dairy.farms.dao.generic.AbstractDAOImpl;
import org.dairy.farms.model.Notes;
import org.springframework.stereotype.Repository;

/**
 * Created by IntelliJ IDEA.
 * User: GDuggira
 * Date: 3 Jan, 2012
 * Time: 5:38:10 PM
 */
@Repository("notesDao" )
public class NotesDAOImpl extends AbstractDAOImpl<Notes,Long> implements NotesDAO {

    /*@Override
    public List<Notes> findByNotesTypeAndNotesForId(Long notesTypeId, Long notesForId) {
        Criteria criteria = basePersistence.getSession().createCriteria(Notes.class);
        criteria.add(Restrictions.eq("notesType",notesTypeId));
        criteria.add(Restrictions.eq("notesFor",notesForId));
        return criteria.list();
    }

    @Override
    public List<Notes> findByNotesTypeNameAndNotesForId(String notesTypeName, Long notesForId) {
        Criteria criteria = basePersistence.getSession().createCriteria(Notes.class);
        criteria.createAlias("notesType","notesType").add(Restrictions.eq("name",notesTypeName));
        criteria.add(Restrictions.eq("notesFor",notesForId));
        return criteria.list();
    }

    @Override
    public Notes addNotes(String notesTypeName, String notes,Long notesForId) {
        NotesType notesType = notesTypeDAO.findByName(notesTypeName);
        if(notesType!=null){
        Notes livestockNotes = new Notes();
        livestockNotes.setNotesFor(notesForId);
        livestockNotes.setNotesType(notesType);
        this.create(livestockNotes);
        return livestockNotes;
        }
        else {
            throw new RuntimeException("Notes type "+notesTypeName+" not found in the DB please check");
        }
    }*/
}
